#include<bits/stdc++.h>
using namespace std;
const int N=202;
const int M=10005;

int n,m;
int s,t;
struct edge{
    int to,next;
    int w;
};
edge edges[M];
int head[N];
int cnt=1;
int ans=0;

void adde(int u,int v,int w){
    edges[cnt].to=v;
    edges[cnt].w=w;
    edges[cnt].next=head[u];
    head[u]=cnt;
    cnt++;
}


int level[N];
int now[N];

bool bfs(){
    memset(level,0x3f,sizeof(level));
    queue<int> que;
    que.push(s);
    level[s]=0;
    now[s]=head[s];
    while(!que.empty()){
        int p=que.front();
        que.pop();
        for(int i=head[p];i!=0;i=edges[i].next){
            int t1=edges[i].to;
            int w=edges[i].w;
            if(w==0) continue;
            if(level[t1]<=n) continue;
            now[t1]=head[t1];
            level[t1]=level[p]+1;
            que.push(t1);
            if(t==t1) return true;
        }
    }
    return false;
}

int dfs(int x,int addv)
{
    if(x==t) return addv;
    int res=0;
    for(int i=now[x];i>0&&addv;i=edges[i].next){
        int t1=edges[i].to;
        int w1=edges[i].w;
        now[x]=i;
        if(w1>0&&level[t1]==level[x]+1)
        {
            int v1=dfs(t1,min(addv,w1));
            if(v1==0) level[t1]=INT_MAX;
            int pos=i,neg;
            if(pos%2==0) neg=pos-1;
            else neg=pos+1;
            edges[pos].w-=v1;
            edges[neg].w+=v1;
            res+=v1;
            addv-=v1;
        }
    }
    return res;
}
int main(){
    scanf("%d%d",&m,&n);
    s=n+1;t=n+2;
    for(int i=1;i<=m;i++){
        adde(s,i,1);
        adde(i,s,0);
    }
    for(int i=m+1;i<=n;i++){
        adde(i,t,1);
        adde(t,i,0);
    }
    while(1){
        int s1,t1;
        scanf("%d%d",&s1,&t1);
        if(s1==-1&&t1==-1) break;
        adde(s1,t1,1);
        adde(t1,s1,0);
    }
    const int inf=INT_MAX;
    while(bfs()){
        ans+=dfs(s,inf);    
    }
    printf("%lld\n",ans);
    int count=0;
    for(int i=2*n+1;count<ans;i+=2){
        if(edges[i].w==0){
            int j=i+1;
            printf("%d %d\n",edges[j].to,edges[i].to);
            count++;
        }
    }
    return 0;
}
